/*
 * @Description: 这是***页面
 * @Date: 2025-09-26 11:03:48
 * @Author: merrychen
 * @LastEditTime: 2025-09-26 11:37:50
 */
import { defineStore } from 'pinia';
import { ref, computed } from 'vue';

// 临时定义类型，避免导入问题
type MessageItem = {
  id: string;
  message: string;
  status: 'local' | 'ai';
  loading?: boolean;
};

export const useDialogueStore = defineStore('dialogue', () => {
  const currentFile = ref<any>(); // 选中的附件
  const currentConversitionUuid = ref<string | undefined>(''); // 当前对话 uuid
  const dialogueRecord = ref<Array<MessageItem>>([]); // 对话记录
  const showHistory = ref<boolean>(false); // 是否是展示对话历史
  const isChatting = ref<boolean>(false); // 正在对话中

  // 获取上面定义的变量值
  const getCurrentFileUuid = computed(() => currentFile.value.uuid);
  const getCurrentFilename = computed(() => currentFile.value.filename);
  const getCurrentConversitionUuid = computed(
    () => currentConversitionUuid.value
  );
  const getDialogueRecord = computed(() => dialogueRecord.value);
  const getShowHistory = computed(() => showHistory.value);
  const getIsChatting = computed(() => isChatting.value);

  // 为上面定义的变量值赋值
  function setCurrentFileInfo(file: any) {
    currentFile.value = file;
  }

  function setCurrentConversitionUuid(uuid: string | undefined) {
    currentConversitionUuid.value = uuid;
  }

  function setDialogueRecord(record: MessageItem[]) {
    dialogueRecord.value = record;
  }

  function setIsChatting(status: boolean) {
    isChatting.value = status;
  }

  function setShowHistory(status: boolean) {
    showHistory.value = status;
  }

  function resetHistory() {
    currentConversitionUuid.value = undefined;
    dialogueRecord.value = [];
    showHistory.value = false;
  }

  return {
    // 状态
    currentFile,
    currentConversitionUuid,
    dialogueRecord,
    showHistory,
    isChatting,
    // 计算属性
    getCurrentFileUuid,
    getCurrentFilename,
    getCurrentConversitionUuid,
    getDialogueRecord,
    getShowHistory,
    getIsChatting,
    // 方法
    setCurrentFileInfo,
    setCurrentConversitionUuid,
    setDialogueRecord,
    setIsChatting,
    setShowHistory,
    resetHistory
  };
});
